package com.zhijiang.util;

import cn.hutool.http.webservice.SoapClient;
import com.alibaba.fastjson.JSONObject;
import com.lowagie.text.DocumentException;
import com.zhijiang.hospital.entity.SysUser;
import com.zhijiang.hospital.entity.dto.HisUserDto;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_datas
 * @description
 * @date 2023-03-20 10:05:00
 */
public class HttpPost {
    private static final String url = "http://172.22.156.34:8888/SPDadjustprice.asmx";

    public static HisUserDto validateUser(SysUser sysUser) {
        SoapClient soapClient = SoapClient.create(url)
                .setMethod("CheckUser", "http://tempuri.org/")
                .setParam("UserName", sysUser.getUsername())
                .setParam("UserPwd", sysUser.getPassword())
                .setConnectionTimeout(15000)
                .setReadTimeout(15000)
                .timeout(15000);
        String result = soapClient.send();
        JSONObject jsonObject = null;
        try {
            jsonObject = XmltoJsonUtil.xmlToJson(result);
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        } catch (org.dom4j.DocumentException e) {
            throw new RuntimeException(e);
        }
        return JSONObject.parseObject(jsonObject.getJSONObject("Envelope").
                getJSONObject("Body").
                getJSONObject("CheckUserResponse").toJSONString(), HisUserDto.class);
    }

    //private static final String REGEX_MOBILE = "((\\+86|0086)?\\s*)((134[0-8]\\d{7})|(((13([0-3]|[5-9]))|(14[5-9])|15([0-3]|[5-9])|(16(2|[5-7]))|17([0-3]|[5-8])|18[0-9]|19(1|[8-9]))\\d{8})|(14(0|1|4)0\\d{7})|(1740([0-5]|[6-9]|[10-12])\\d{7}))";
    //private static final String REGEX_MOBILE = "(/^1[3-9]{1}[0-9]{9}$/)";
    //Pattern p = Pattern.compile("^1(3\\d{2}|4[14-9]\\d|5([0-35689]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[13589]\\d)\\d{7}$");


    //public static boolean isOkMobile(String phone) {
    //    if (StringUtils.isBlank(phone)) {
    //        return false;
    //    }
    //    return Pattern.matches(REGEX_MOBILE, phone);
    //}
}
